1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.Drag; 26 27 private import gdk.ContentFormats; 28 private import gdk.ContentProvider; 29 private import gdk.Device; 30 private import gdk.Display; 31 private import gdk.Surface; 32 private import gdk.c.functions; 33 public import gdk.c.types; 34 private import gobject.ObjectG; 35 private import gobject.Signals; 36 private import std.algorithm; 37 38 39 /** 40 * The `GdkDrag` object represents the source of an ongoing DND operation. 41 * 42 * A `GdkDrag` is created when a drag is started, and stays alive for duration of 43 * the DND operation. After a drag has been started with [func@Gdk.Drag.begin], 44 * the caller gets informed about the status of the ongoing drag operation 45 * with signals on the `GdkDrag` object. 46 * 47 * GTK provides a higher level abstraction based on top of these functions, 48 * and so they are not normally needed in GTK applications. See the 49 * "Drag and Drop" section of the GTK documentation for more information. 50 */ 51 public class Drag : ObjectG 52 { 53 /** the main Gtk struct */ 54 protected GdkDrag* gdkDrag; 55 56 /** Get the main Gtk struct */ 57 public GdkDrag* getDragStruct(bool transferOwnership = false) 58 { 59 if (transferOwnership) 60 ownedRef = false; 61 return gdkDrag; 62 } 63 64 /** the main Gtk struct as a void* */ 65 protected override void* getStruct() 66 { 67 return cast(void*)gdkDrag; 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GdkDrag* gdkDrag, bool ownedRef = false) 74 { 75 this.gdkDrag = gdkDrag; 76 super(cast(GObject*)gdkDrag, ownedRef); 77 } 78 79 80 /** */ 81 public static GType getType() 82 { 83 return gdk_drag_get_type(); 84 } 85 86 /** 87 * Starts a drag and creates a new drag context for it. 88 * 89 * This function is called by the drag source. After this call, you 90 * probably want to set up the drag icon using the surface returned 91 * by [method@Gdk.Drag.get_drag_surface]. 92 * 93 * This function returns a reference to the [class@Gdk.Drag] object, 94 * but GTK keeps its own reference as well, as long as the DND operation 95 * is going on. 96 * 97 * Note: if @actions include %GDK_ACTION_MOVE, you need to listen for 98 * the [signal@Gdk.Drag::dnd-finished] signal and delete the data at 99 * the source if [method@Gdk.Drag.get_selected_action] returns 100 * %GDK_ACTION_MOVE. 101 * 102 * Params: 103 * surface = the source surface for this drag 104 * device = the device that controls this drag 105 * content = the offered content 106 * actions = the actions supported by this drag 107 * dx = the x offset to @device's position where the drag nominally started 108 * dy = the y offset to @device's position where the drag nominally started 109 * 110 * Returns: a newly created `GdkDrag` 111 */ 112 public static Drag begin(Surface surface, Device device, ContentProvider content, GdkDragAction actions, double dx, double dy) 113 { 114 auto __p = gdk_drag_begin((surface is null) ? null : surface.getSurfaceStruct(), (device is null) ? null : device.getDeviceStruct(), (content is null) ? null : content.getContentProviderStruct(), actions, dx, dy); 115 116 if(__p is null) 117 { 118 return null; 119 } 120 121 return ObjectG.getDObject!(Drag)(cast(GdkDrag*) __p, true); 122 } 123 124 /** 125 * Informs GDK that the drop ended. 126 * 127 * Passing %FALSE for @success may trigger a drag cancellation 128 * animation. 129 * 130 * This function is called by the drag source, and should be the 131 * last call before dropping the reference to the @drag. 132 * 133 * The `GdkDrag` will only take the first [method@Gdk.Drag.drop_done] 134 * call as effective, if this function is called multiple times, 135 * all subsequent calls will be ignored. 136 * 137 * Params: 138 * success = whether the drag was ultimatively successful 139 */ 140 public void dropDone(bool success) 141 { 142 gdk_drag_drop_done(gdkDrag, success); 143 } 144 145 /** 146 * Determines the bitmask of possible actions proposed by the source. 147 * 148 * Returns: the `GdkDragAction` flags 149 */ 150 public GdkDragAction getActions() 151 { 152 return gdk_drag_get_actions(gdkDrag); 153 } 154 155 /** 156 * Returns the `GdkContentProvider` associated to the `GdkDrag` object. 157 * 158 * Returns: The `GdkContentProvider` associated to @drag. 159 */ 160 public ContentProvider getContent() 161 { 162 auto __p = gdk_drag_get_content(gdkDrag); 163 164 if(__p is null) 165 { 166 return null; 167 } 168 169 return ObjectG.getDObject!(ContentProvider)(cast(GdkContentProvider*) __p); 170 } 171 172 /** 173 * Returns the `GdkDevice` associated to the `GdkDrag` object. 174 * 175 * Returns: The `GdkDevice` associated to @drag. 176 */ 177 public Device getDevice() 178 { 179 auto __p = gdk_drag_get_device(gdkDrag); 180 181 if(__p is null) 182 { 183 return null; 184 } 185 186 return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p); 187 } 188 189 /** 190 * Gets the `GdkDisplay` that the drag object was created for. 191 * 192 * Returns: a `GdkDisplay` 193 */ 194 public Display getDisplay() 195 { 196 auto __p = gdk_drag_get_display(gdkDrag); 197 198 if(__p is null) 199 { 200 return null; 201 } 202 203 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p); 204 } 205 206 /** 207 * Returns the surface on which the drag icon should be rendered 208 * during the drag operation. 209 * 210 * Note that the surface may not be available until the drag operation 211 * has begun. GDK will move the surface in accordance with the ongoing 212 * drag operation. The surface is owned by @drag and will be destroyed 213 * when the drag operation is over. 214 * 215 * Returns: the drag surface 216 */ 217 public Surface getDragSurface() 218 { 219 auto __p = gdk_drag_get_drag_surface(gdkDrag); 220 221 if(__p is null) 222 { 223 return null; 224 } 225 226 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 227 } 228 229 /** 230 * Retrieves the formats supported by this `GdkDrag` object. 231 * 232 * Returns: a `GdkContentFormats` 233 */ 234 public ContentFormats getFormats() 235 { 236 auto __p = gdk_drag_get_formats(gdkDrag); 237 238 if(__p is null) 239 { 240 return null; 241 } 242 243 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p); 244 } 245 246 /** 247 * Determines the action chosen by the drag destination. 248 * 249 * Returns: a `GdkDragAction` value 250 */ 251 public GdkDragAction getSelectedAction() 252 { 253 return gdk_drag_get_selected_action(gdkDrag); 254 } 255 256 /** 257 * Returns the `GdkSurface` where the drag originates. 258 * 259 * Returns: The `GdkSurface` where the drag originates 260 */ 261 public Surface getSurface() 262 { 263 auto __p = gdk_drag_get_surface(gdkDrag); 264 265 if(__p is null) 266 { 267 return null; 268 } 269 270 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 271 } 272 273 /** 274 * Sets the position of the drag surface that will be kept 275 * under the cursor hotspot. 276 * 277 * Initially, the hotspot is at the top left corner of the drag surface. 278 * 279 * Params: 280 * hotX = x coordinate of the drag surface hotspot 281 * hotY = y coordinate of the drag surface hotspot 282 */ 283 public void setHotspot(int hotX, int hotY) 284 { 285 gdk_drag_set_hotspot(gdkDrag, hotX, hotY); 286 } 287 288 /** 289 * Emitted when the drag operation is cancelled. 290 * 291 * Params: 292 * reason = The reason the drag was cancelled 293 */ 294 gulong addOnCancel(void delegate(GdkDragCancelReason, Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 295 { 296 return Signals.connect(this, "cancel", dlg, connectFlags ^ ConnectFlags.SWAPPED); 297 } 298 299 /** 300 * Emitted when the destination side has finished reading all data. 301 * 302 * The drag object can now free all miscellaneous data. 303 */ 304 gulong addOnDndFinished(void delegate(Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 305 { 306 return Signals.connect(this, "dnd-finished", dlg, connectFlags ^ ConnectFlags.SWAPPED); 307 } 308 309 /** 310 * Emitted when the drop operation is performed on an accepting client. 311 */ 312 gulong addOnDropPerformed(void delegate(Drag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 313 { 314 return Signals.connect(this, "drop-performed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 315 } 316 }